import React, { Component } from 'react';
import styled from 'styled-components';

const Item = styled.li`
    overflow: hidden;
    padding-bottom: 10px;
    .avatar {
        width: 40px;
        height: 40px;
        border-radius: 20px;
        float: ${props => props.self ? 'right' : 'left'};
        margin: 10px 10px 0;
    }
    .name {
        color: #bbb;
        text-align: ${props => props.self ? 'right' : 'left'};
        line-height: 24px;
    }
    .content {
        display: inline-block;
        max-width: calc(100% - 130px);
        font-size: 12px;
        line-height: 20px;
        padding: 5px;
        background-color: ${props => props.self ? '#108ee9' : '#fff'};
        color: ${props => props.self ? '#fff' : '#000'};
        float: ${props => props.self ? 'right' : 'left'};
        position: relative;
        border-radius: 5px;
        &:after {
            position: absolute;
            content: '';
            border-width: 5px;
            border-style: solid;
            height: 0;
            width: 0;
            overflow: hidden;
            top: 10px;
            left: ${props => props.self ? 'calc(100% - 1px)' : '-10px'};
            border-top-color: transparent;
            border-bottom-color: transparent;
            border-right-color: ${props => props.self ? 'transparent' : '#fff'};
            border-left-color: ${props => props.self ? '#108ee9' : 'transparent'};
        }
    }
`

export default function ChatItem(props) {
    return (
        <Item self={props.self}>
            <img className='avatar' src='http://www.qqzhi.com/uploadpic/2015-01-22/073441407.jpg'/>
            <p className='name'>{props.username}</p>
            <p className='content'>{props.content}</p>      
        </Item>
    )
}